const Service = require("egg").Service;

class UserService extends Service {
    async login() {
        const { ctx, app } = this;
        const {
            username,
            password
        } = ctx.request.body;
        const md5 = require("md5")
        const jwt = require("jsonwebtoken")
        let res = await app.mysql.get("user", { username, password: md5(password) });
        if (res) {
            return {
                message: "登录成功！",
                code: 200,
                userData: res,
                token: jwt.sign(JSON.stringify(res), ctx.app.config.keys)
            }
        } else {
            return "账号密码错误"
        }

    }

    async getList() {
        const { ctx, app } = this;
        let res = await app.mysql.select("agent");
        return res
    }

}
module.exports = UserService;